package controller;

import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import service.DonationService;
import vo.DepartmentVO;
import vo.DonationVO;
import vo.MemberVO;
import vo.OrganizationVO;

@Controller
public class DonationController {
	
	@Resource(name = "donationServiceImpl")
	private DonationService donationService;

	@RequestMapping("stepup_donation.sds")
	public String donationPage(MemberVO vo){
		return "stepup_donation";
	}
	
	@RequestMapping("stepup_donationUpdate.sds")
	public String donationUpdate(MemberVO vo, HttpSession session){
		System.out.println("ctrl stepup_donation");
		System.out.println(">>>>>>>>>>>>>>>>>> vo: " + vo);
		
		int ocredbean = vo.getMredbean();
		
		MemberVO rmvo = donationService.updateDonation(vo);
		
		MemberVO mvo = (MemberVO) session.getAttribute("loginMember");
		mvo.setMredbean(rmvo.getMredbean());
		session.setAttribute("loginMember", mvo);
		
		int updateOrganization = donationService.updateOrganization(vo);
		
		
		
		return "stepup_donation";
	}
	
	@RequestMapping("stepup_donationdetail.sds")
	public String donationDetailPage(OrganizationVO vo,Model model){
		System.out.println("ctrl stepup_donationdetail");
		System.out.println(">>>>>> "+vo.getOno()); 
		
		OrganizationVO result = donationService.donationDetail(vo.getOno());
		model.addAttribute("dodetail", result) ;
		System.out.println(result);
		return "stepup_donationdetail";
	}
	
	@RequestMapping("stepup_donation_list.sds")
	@ResponseBody
	public HashMap donation(HttpSession session){
		System.out.println("ctrl donation");
		MemberVO mvo = (MemberVO) session.getAttribute("loginMember");
		HashMap map = donationService.organization(mvo);
		
		return map;
	}
	
	@RequestMapping("stepup_donationdetail_list.sds")
	@ResponseBody
	public List<DonationVO> donationlist(HttpSession session){
		System.out.println("ctrl donationlist");
		
		MemberVO mvo = (MemberVO) session.getAttribute("loginMember");
		HashMap map = new HashMap();
		
		List<DonationVO> map_donation = donationService.donationlist(mvo);
		map.put("getdonationlist", map_donation);
		
		System.out.println(map);
		
		return map_donation;
	}
	
}
